﻿@model TidyBlog.MVC.WWW.Models.ListWithPaginator<TidyBlog.Entity.Article>

@{
	ViewBag.Title = "文章管理";
	Layout = "~/Views/Shared/_ManageLayout.cshtml";
}

<form action="@Url.Action("List")" method="get">
	<table class="fourCols">
		<thead>
			<tr>
				<th colspan="4">搜索</th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="4" class="buttons">
					<input type="submit" value="搜 索" />
					<input type="reset" value="清 空" data-isclear="true" />
				</td>
			</tr>
		</tfoot>
		<tbody>
			<tr>
				<th><label for="title">关键字：</label></th>
				<td><input type="text" id="title" name="title" maxlength="80" value="@Model.SearchParams["title"]" /></td>
				<th><label for="categoryid">分　类：</label></th>
				<td>
					<select id="categoryid" name="categoryid">
						<option value="">未指定</option>
@if (ViewBag.CategoryList != null)
{
	foreach (var category in ViewBag.CategoryList)
	{
		if (Model.SearchParams["categoryid"] == category.CategoryId.ToString())
		{
						<option value="@category.CategoryId" selected="selected">@category.CategoryName</option>
		}
		else
		{
						<option value="@category.CategoryId">@category.CategoryName</option>
		}
	}
}
					</select>
				</td>
			</tr>
		</tbody>
	</table>
</form>

@if (Model.Result != null)
{
<table>
	<thead>
		<tr>
			<th style="width: 5%;">编号</th>
			<th style="width: 24%;">标题</th>
			<th style="width: 14%;">分类</th>
			<th style="width: 12%;">作者</th>
			<th style="width: 5%;">权重</th>
			<th style="width: 18%;">发表时间</th>
			<th style="width: 10%;">状态</th>
			<th style="width: 12%;">操作</th>
		</tr>
	</thead>
	@if (Model.Result.PageCount > 1)
	{
	<tfoot>
		<tr><td colspan="8">@{ Html.RenderPartial("_paginator", Model.ResultPaginator); }</td></tr>
	</tfoot>
	}
	<tbody>
	@if (Model.Result.Data == null || Model.Result.Data.Count == 0)
	{
		<tr><td colspan="8">暂无符合条件的数据</td></tr>
	}
	else
	{
		foreach (var article in Model.Result.Data)
		{
			var routeValues = new { id = article.ArticleId };
		<tr>
			<td>@article.ArticleId</td>
			<td><a href="@Url.Action("Detail", "Article", routeValues)" target="_blank">@article.Title</a></td>
			<td>@article.CategoryName</td>
			<td>@article.AuthorName</td>
			<td>@article.Weight</td>
			<td>@article.PostTime.AddHours(ViewBag.Setup.TimeZone).ToString("yyyy-MM-dd HH:mm:ss")</td>
			<td style="text-align: center;">@article.StateText</td>
			<td style="text-align: center; word-spacing: 1em;">
				<a href="@Url.Action("Edit", routeValues)">编辑</a>
				<a href="@Url.Action("Delete", routeValues)" class="delete-confirm">删除</a>
			</td>
		</tr>
		}
	}
	</tbody>
</table>
}

@section Script{
<script>
require('dom/1.0.x/', function($) {
	$('a.delete-confirm').click(function(e) {
		if ( !window.confirm('确认要删除此文章吗（此操作不可恢复）？') ) {
			e.preventDefault();
		}
	});
});
</script>
}